#include <iostream>

template<class T>
void swap(T &left, T &right)
{
    left = left ^ right;
    right = left ^ right;
    left = left ^ right;
}

template<class T>
void swap2(T &left, T &right)
{
    T tmp = left;
    left = right;
    right = tmp;
}

template<class T>
void swap3(T *pl, T *pr)
{
    *pl = *pl ^ *pr;
    *pr = *pl ^ *pr;
    *pl = *pl ^ *pr;
}

int main(int argc, const char *argv[])
{
    char ch1 = 'a', ch2 = 'z';
    int i1 = 10, i2 = 99;
    double f1 = 10.323, f2 = 989.33;
    std::cout << "the src is (" << ch1 << "," << ch2 << ") ";
    swap(ch1, ch2);
    std::cout << "swap with ^ is (" << ch1 << "," << ch2 << ")" << std::endl;

    std::cout << "the src is (" << i1 << "," << i2 << ") ";
    swap(i1, i2);
    std::cout << "swap with ^ is (" << i1 << "," << i2 << ")" << std::endl;

    std::cout << "using ptr." << std::endl;
    swap3(&ch1, &ch2);
    std::cout << "swap with ^ is (" << ch1 << "," << ch2 << ")" << std::endl;
    swap3(&i1, &i2);
    std::cout << "swap with ^ is (" << i1 << "," << i2 << ")" << std::endl;

    return 0;
}
